package com.shangpintechnology.sci.view;

import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;

import javax.swing.DefaultListSelectionModel;
import javax.swing.JOptionPane;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;

import com.shangpintechnology.sci.DAO;
import com.shangpintechnology.sci.MainClass;
import com.shangpintechnology.sci.machinegenerat.ArrangeWaiter__;

public class ArrangeWaiter extends
		ArrangeWaiter__ implements ListSelectionListener{
	
	public ArrangeWaiter(Frame parent, boolean modal) {
		super(parent, modal);
		 this.setLocation(300, 200);
		DAO dao = new DAO();
		jTable1.setModel(new DefaultTableModel(
				dao.getStuffArray2(),new String[]{"编号","姓名"}));
		
		jButton1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				dispose();
			/**/
			}
		});
		jTable1.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
		jTable1.getSelectionModel().addListSelectionListener(this);
	}

	@Override
	public void valueChanged(ListSelectionEvent e) {
		try{
		 
		// 添加安排人员信息到当前客户面板
		DefaultListSelectionModel listSelectionModel = (DefaultListSelectionModel)e.getSource();
		int row = listSelectionModel.getMinSelectionIndex(); 
		String name1 = (String) (this.jTable1.getValueAt(row, 1));
		MainClass m = MainClass.getSingleton();
		m.getView().getWaiterInfo().setText("接待："+	name1);
		DAO dao = new DAO();
		String currentVipCode = MainClass.getSingleton().getView().getVIPcode().getText();
		String waiterCode = (String)(this.jTable1.getValueAt(row, 0));
		JOptionPane.showMessageDialog(null, waiterCode);
		
		dao.updateServiceHistory(waiterCode,currentVipCode);
		
		}catch (Exception e1)
        {
        e1.printStackTrace();
        }finally    {
			getThis().setVisible(false);
		}
	}
	
}
